package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.CheckOutMethodModel;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24 0024.
 * 选择支付方式列表适配器
 */

public class PayMethodAdapter extends BaseAdapter{

    private Context t;
    private List<CheckOutMethodModel.PCashierPayListDtosBean> mList;//11-现金；12-微信；13-支付宝；14-银行卡；15-支票；16-转应收；17-长短款；18-招待；21-预收现金；
    // 22-预收微信；23-预收支付宝；24-预收银行卡；25-预收支票；26-信用卡预授权；
    private int index;//当前选中的位置
    public PayMethodAdapter(Context context, List<CheckOutMethodModel.PCashierPayListDtosBean> list){
        this.t=context;
        this.mList=list;
        this.index=0;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    ViewHolder holder;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CheckOutMethodModel.PCashierPayListDtosBean model=mList.get(position);
        if(convertView==null){
            convertView= LayoutInflater.from(t).inflate(R.layout.pay_method_list_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder= (ViewHolder) convertView.getTag();
        if(index==position){
            holder.isSel.setVisibility(View.VISIBLE);
            holder.tvFlag.setTextColor(t.getResources().getColor(R.color.orange_color));
        }else{
            holder.isSel.setVisibility(View.INVISIBLE);
            holder.tvFlag.setTextColor(t.getResources().getColor(R.color.whitetext));
        }
        switch (model.getType()){
            case 11://现金
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.cash_pay));
                break;
            case 12://微信
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.weChat_pay));
                break;
            case 13://支付宝
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.ali_pay));
                break;
            case 14://银行卡
                holder.ivflag.setImageResource(R.mipmap.yinhangkazhifu);
                holder.tvFlag.setText(t.getString(R.string.bank_card_pay));
                break;
            case 15://支票
                holder.ivflag.setImageResource(R.mipmap.fapiao);
                holder.tvFlag.setText(t.getString(R.string.check_pay));
                break;
            case 16://转应收
                holder.ivflag.setImageResource(R.mipmap.zhuanyingshou);
                holder.tvFlag.setText(t.getString(R.string.transfer_receivable));
                break;
            case 17://长短款
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.Short_and_long_payment));
                break;
            case 18://招待
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.entertain));
                break;
            case 21://预收现金
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.Collect_in_advance_cash));
                break;
            case 22://预收微信
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.Collect_in_advance_weChat));
                break;
            case 23://预收支付宝
                holder.ivflag.setImageResource(R.mipmap.xianjinzhifu);
                holder.tvFlag.setText(t.getString(R.string.Collect_in_advance_ali));
                break;
            case 24://预收银行卡
                holder.ivflag.setImageResource(R.mipmap.yinhangkazhifu);
                holder.tvFlag.setText(t.getString(R.string.Collect_in_advance_bank));
                break;
            case 25://预收支票
                holder.ivflag.setImageResource(R.mipmap.fapiao);
                holder.tvFlag.setText(t.getString(R.string.Collect_in_advance_check));
                break;
            case 26://信用卡预授权
                holder.ivflag.setImageResource(R.mipmap.xinyongkezhifu);
                holder.tvFlag.setText(t.getString(R.string.Credit_card_pre_authorization));
                break;
        }
        return convertView;
    }

    public void setIndex(int index){
        this.index=index;
        notifyDataSetChanged();
    }
    public Integer getIndex(){
        return index;
    }

    public class ViewHolder{
        ImageView ivflag;//图片标识
        TextView tvFlag;//文字
        ImageView isSel;//是否选中

        public ViewHolder(View view){
            ivflag= (ImageView) view.findViewById(R.id.iv_flag);
            tvFlag= (TextView) view.findViewById(R.id.tv_flag);
            isSel= (ImageView) view.findViewById(R.id.iv_is_sel);
        }
    }

}
